/**
 * 35. 搜索插入位置
 */
class Solution4 {
    public int searchInsert(int[] nums, int target) {
        int ret = -1, left = 0, right = nums.length - 1;

        while(left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] >= target) {
                right = mid;
            } else {
                // nums[mid] < target
                left = mid + 1;
            }
        }

        return nums[left] >= target ? left : left + 1;
    }
}